//package com.xls.commonlibrary.ad.sigmob.ads;
//
//import android.app.Activity;
//import android.util.Log;
//import android.view.View;
//import android.view.ViewGroup;
//import android.webkit.ValueCallback;
//import android.widget.FrameLayout;
//import android.widget.RelativeLayout;
//
//import androidx.appcompat.app.AppCompatActivity;
//import androidx.lifecycle.DefaultLifecycleObserver;
//import androidx.lifecycle.LifecycleOwner;
//
//import com.windmill.sdk.WindMillError;
//import com.windmill.sdk.models.AdInfo;
//import com.windmill.sdk.splash.IWMSplashEyeAd;
//import com.windmill.sdk.splash.WMSplashAd;
//import com.windmill.sdk.splash.WMSplashAdListener;
//import com.windmill.sdk.splash.WMSplashAdRequest;
//import com.windmill.sdk.splash.WMSplashEyeAdListener;
//import com.xls.commonlibrary.ad.sigmob.ads.splash.SplashZoomOutManager;
//import com.xls.commonlibrary.app.MainApplication;
//
//import io.reactivex.rxjava3.annotations.NonNull;
//
//// 腾讯开屏广告
//public class SigmobSplashUtil {
//
////    private String posId = "9093517612222759"; //  demo id
//
//    private String placementId = "6186551234814820"; // 正式 id
//
//    private String TAG = "TxUtil";
//
//    private static volatile SigmobSplashUtil singleton = null;
//
//    private SigmobSplashUtil() {
//    }
//
//    public static SigmobSplashUtil getInstance() {
//        if (singleton == null) {
//            synchronized (SigmobSplashUtil.class) {
//                if (singleton == null) {
//                    singleton = new SigmobSplashUtil();
//                }
//            }
//        }
//        return singleton;
//    }
//
//
//    AppCompatActivity activity;
//    ValueCallback<Boolean> valueCallback;
//
//    public void loadSplash(@NonNull AppCompatActivity activity,
//                           @NonNull FrameLayout container,
//                           @NonNull ValueCallback<Boolean> valueCallback
//    ) {
//
//        this.activity = activity;
//        this.valueCallback = valueCallback;
//
//        // sigmob 没有用到
////        this.mSplashContainer = container;
//
//        addLifecycle();
//
//        loadSplashAd();
//
//    }
//
//    private void callbackSuccess() {
//        if (this.valueCallback == null) return;
//        this.valueCallback.onReceiveValue(true);
//    }
//
//    private void callbackFail() {
//        if (this.valueCallback == null) return;
//        this.valueCallback.onReceiveValue(false);
//    }
//
//
//    private void addLifecycle() {// 重要
//        if (this.activity == null) return;
//
//        this.activity.getLifecycle().addObserver(new DefaultLifecycleObserver() {
//            // 还有很多生命周期都可以感知
//            // 这里只关注 onDestroy()的注销ad对象
//            @Override
//            public void onDestroy(LifecycleOwner owner) {
//                DefaultLifecycleObserver.super.onDestroy(owner);
////                Logger.d("===========LifecycleOwner=========onDestroy===========");
//
//
//                /** 6、在onDestroy中销毁广告 */
//                if (splashLY != null) {
//                    splashLY.removeAllViews();
//                    splashLY.setVisibility(View.GONE);
//                }
//
//            }
//        });
//    }
//
//
//    /////////////////////////////////   以下SDK代码   ////////////////////////////////////////////
//
//
//    private FrameLayout mSplashContainer;
//
//    private ViewGroup splashLY;
//    private WMSplashAd splashAd;
//
//
//    private void initViewGroup(Activity activity) {
//
////        if (this.splashLY != null) {
////            if (this.splashLY.getParent() != null) {
////                ((ViewGroup) this.splashLY.getParent()).removeView(this.splashLY);
////            }
////
////            this.splashLY = null;
////        }
//
//        splashLY = new RelativeLayout(activity);
//        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
//        ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();
//        viewGroup.addView(splashLY, layoutParams);
//    }
//
//    private void loadSplashAd() {
//
//        initViewGroup(activity);
//
//        WMSplashAdRequest adRequest = new WMSplashAdRequest(placementId, String.valueOf(0), null);
//        splashAd = new WMSplashAd(activity, adRequest, new WMSplashAdListener() {
//            @Override
//            public void onSplashAdSuccessPresent(AdInfo adInfo) {
//            }
//
//            @Override
//            public void onSplashAdSuccessLoad(String placementId) {
//                showSplashAd();
//            }
//
//            @Override
//            public void onSplashAdFailToLoad(WindMillError error, String placementId) {
//                Log.d("lance", "onError:" + error.toString() + ":" + placementId);
//
//                if (splashLY != null) {
//                    splashLY.removeAllViews();
//                    splashLY.setVisibility(View.GONE);
//                }
//
//                callbackFail();
//            }
//
//            @Override
//            public void onSplashAdClicked(AdInfo adInfo) {
//            }
//
//            @Override
//            public void onSplashClosed(AdInfo adInfo, IWMSplashEyeAd splashEyeAd) {
//                //（1）当穿山甲、优量汇的开屏广告素材支持点睛时，splashEyeAd不为null
//                //（2）当展示的是快手开屏广告时，splashEyeAd为非null值，但不一定表示此次快手开屏广告的素材支持点睛，不支持时调用IATSplashEyeAd#show()方法会直接回调ATSplashEyeAdListener#onAdDismiss()方法
//                //（3）当splashEyeAd不为null，但是开发者不想支持点睛功能时，必须调用splashEyeAd.destroy()释放资源，然后跳转主页面或者移除开屏View
//                if (splashLY != null) {
//                    splashLY.removeAllViews();
//                    splashLY.setVisibility(View.GONE);
//                }
//                //展示点睛广告
//                showSplashEyeAd(splashEyeAd);
//            }
//        });
//
//        splashAd.loadAdOnly();
//    }
//
//    private void showSplashAd() {
//        if (splashAd != null && splashAd.isReady()) {
////            splashAd.showAd(null);
//            splashAd.showAd(splashLY);
//        } else {
//        }
//    }
//
//    private void showSplashEyeAd(final IWMSplashEyeAd splashEyeAd) {
//        if (splashEyeAd == null) {
//
//
//            callbackSuccess();
//
//
//            return;
//        }
//        splashEyeAd.show(activity, null, new WMSplashEyeAdListener() {
//            @Override
//            public void onAnimationStart(View splashView) {
//                Log.i("lance", "----------onAnimationStart---------: eye ad");
//                //执行缩放动画
//                SplashZoomOutManager zoomOutManager = SplashZoomOutManager.getInstance(MainApplication.getAppContext());
//
//                ////建议优先使用IATSplashEyeAd#getSuggestedSize()返回的大小作为缩放动画的目标大小
//                int[] suggestedSize = splashEyeAd.getSuggestedSize(MainApplication.getAppContext());
//                if (suggestedSize != null) {
//                    zoomOutManager.setSplashEyeAdViewSize(suggestedSize[0], suggestedSize[1]);
//                }
//
////                zoomOutManager.setSplashInfo(splashView, SplashAdActivity.this.getWindow().getDecorView());
//                ViewGroup content = activity.findViewById(android.R.id.content);
//                zoomOutManager.startZoomOut(splashView, content, content, new SplashZoomOutManager.AnimationCallBack() {
//
//                    @Override
//                    public void animationStart(int animationTime) {
//                        Log.i("lance", "----------animationStart---------: eye ad");
//                    }
//
//                    @Override
//                    public void animationEnd() {
//                        Log.i("lance", "----------animationEnd---------: eye ad");
//                        //当缩放动画完成时必须调用IATSplashEyeAd#onFinished()通知SDK
//                        splashEyeAd.onFinished();
//                    }
//                });
//            }
//
//            @Override
//            public void onAdDismiss(boolean isSupportEyeSplash) {
//                Log.i("lance", "----------onAdDismiss---------:" + isSupportEyeSplash);
//                //建议在此回调中调用IATSplashEyeAd#destroy()释放资源以及释放其他资源，以免造成内存泄漏
//                SplashZoomOutManager zoomOutManager = SplashZoomOutManager.getInstance(MainApplication.getAppContext());
//                zoomOutManager.clearStaticData();
//                splashEyeAd.destroy();
//
//
//                callbackSuccess();
//            }
//        });
//    }
//
//}
